<?php

require 'conf.inc.php'; 


function print_item ($i) {
  
  global $products;
  
  $item = '';
 
  $item = '<div class="ui-grid-solo" style="text-align:center">';
  $item .= '<div class="ui-block-a"> 
              <div class="ui-bar"><a data-parm="ciao" href="#two"><img src="' . $products['riviste'][$i]['image_src'] . '"/></a></div></div>';  
  $item .= '<div class="ui-block-a"> 
              <div class="ui-bar" style="height:15px; font-size: 11px">' . $products['riviste'][$i]['description'] . '</div></div>';
  // $item .= '<div class="ui-block-a">
              // <div class="ui-bar" style="height:10px; font-size: 12px; color: darkred">' . $products['riviste'][$i]['price_label'] . '</div></div>';
  $item .= '</div>'; 
  
  return $item;
  
}

function print_list ($type,$budget,array $g) {
   
    
    $j=0;
    
    global $products;
    
    
    // echo '<ul data-role="listview">
      // <li><a href="#">Acura</a></li>
      // <li><a href="#">Audi</a></li>
      // <li><a href="#">BMW</a></li>
      // <li><a href="#">Cadillac</a></li>
      // <li><a href="#">Ferrari</a></li>
    // </ul>';
    
    
    //class="ui-icon-alt" data-role="listview" data-inset="false" data-filter="true" data-filter-placeholder="Cerca">
   // echo '<ul id="thelist">    
   	$strHTML ="";
   foreach($products[$type] as $prod){
	
	if($prod['price']>$budget) continue;
	if(!in_array($prod['gender'],$g)) continue;
    $strHTML.= '<li><a class="show-page-loading-msg" href="#scheda_prodotto" data-parm="'. $prod['id'] .'">
          <img src="' . $prod['image_src'] . '"/>
          <h2 style="white-space:normal;">' . $prod['short_description'] . '</h2>
          <p style="white-space:normal;">';
		  if(strlen($prod['description'])>30)
		  			// non taglia le parole a meta'
			      $strHTML.= preg_replace('/\s+?(\S+)?$/', '', substr($prod['description'], 0, 30)) . ' ...';
			else
				    $strHTML.=$prod['description'];
    $strHTML.=' </p> </a> </li>';   
   }
   echo $strHTML;
//    echo '<li><a class="show-page-loading-msg" href="#scheda_prodotto" data-parm="'. $products['riviste'][0]['id'] .'">
//          <img src="' . $products['riviste'][0]['image_src'] . '"/>
//          <h2>' . $products['riviste'][0]['description'] . '</h2>
//          </a>
//        </li>
//        <li><a class="show-page-loading-msg" href="#scheda_prodotto" data-parm="'. $products['riviste'][1]['id'] .'">
//          <img src="' . $products['riviste'][1]['image_src'] . '"/>
//          <h2>' . $products['riviste'][1]['description'] . '</h2>
//          </a>
//        </li>
//        <li><a class="show-page-loading-msg" href="#scheda_prodotto" data-parm="'. $products['riviste'][2]['id'] .'">
//          <img src="' . $products['riviste'][2]['image_src'] . '"/>
//          <h2>' . $products['riviste'][2]['description'] . '</h2>
//          </a>
//        </li> 
//        <li><a class="show-page-loading-msg" href="#scheda_prodotto" data-parm="'. $products['riviste'][3]['id'] .'">
//          <img src="' . $products['riviste'][3]['image_src'] . '"/>
//          <h2>' . $products['riviste'][3]['description'] . '</h2>
//          </a>
//        </li> 
//        <li><a class="show-page-loading-msg" href="#scheda_prodotto" data-parm="'. $products['riviste'][4]['id'] .'">
//          <img src="' . $products['riviste'][4]['image_src'] . '"/>
//          <h2>' . $products['riviste'][4]['description'] . '</h2>
//          </a>
//        </li>
//    		<li><a class="show-page-loading-msg" href="#scheda_prodotto" data-parm="'. $products['riviste'][4]['id'] .'">
//          <img src="' . $products['riviste'][4]['image_src'] . '"/>
//          <h2>' . $products['riviste'][4]['description'] . '</h2>
//          </a>
//        </li>
//        <li><a class="show-page-loading-msg" href="#scheda_prodotto" data-parm="'. $products['riviste'][4]['id'] .'">
//          <img src="' . $products['riviste'][4]['image_src'] . '"/>
//          <h2>' . $products['riviste'][4]['description'] . '</h2>
//          </a>
//        </li>'; // </ul>';

/*    echo '<div class="block description">
    <a href="#">
           <img src="' . $products['riviste'][0]['image_src'] . '"/>
           <p>' . $products['riviste'][0]['description'] . '</p>
           </a>
    </div>
    <div class="block">  Pretty row 2 </div>
    <div class="block description">
    <a href="#">
           <img src="' . $products['riviste'][0]['image_src'] . '"/>
           <p>' . $products['riviste'][0]['description'] . '</p>
           </a>    
           </div>
    <div class="block">  Pretty row 2 </div>
    <div class="block description">
    <a href="#">
           <img src="' . $products['riviste'][0]['image_src'] . '"/>
           <p>' . $products['riviste'][0]['description'] . '</p>
           </a>
    </div>
    <div class="block">  Pretty row 2 </div>
    <div class="block description">
    <a href="#">
           <img src="' . $products['riviste'][0]['image_src'] . '"/>
           <p>' . $products['riviste'][0]['description'] . '</p>
           </a>
    </div>
    <div class="block">  Pretty row 2 </div>
    <div class="block description">
    <a href="#">
           <img src="' . $products['riviste'][0]['image_src'] . '"/>
           <p>' . $products['riviste'][0]['description'] . '</p>
           </a>
    </div>
    <div class="block">  Pretty row 2 </div>
    <div class="block description">
    <a href="#">
           <img src="' . $products['riviste'][0]['image_src'] . '"/>
           <p>' . $products['riviste'][0]['description'] . '</p>
           </a>
    </div>
    <div class="block">  Pretty row 2 </div>
    ';
*/
   
  }



  //print_r($_POST);

  //$product_type = (isset($_POST['item_type'])) ? $_POST['item_type'] : '';  

	if(isset($_POST['item_type']) && isset($_POST['budget']) && isset($_POST['tipo'])){
		switch(strtolower($_POST['tipo'])){
			case "male":
				$gender=array("M/F","M");
				break;
			case "female":
				$gender=array("M/F","F");
				break;
			case "couple":
				$gender=array("M/F");
				break;
		}
		
		print_list($_POST['item_type'],$_POST['budget'],$gender);
	}
	

/*  
  switch ($product_type) 
  { 
          case 'riviste':   
            print_list('riviste');
            break; 
          case 'libri':   
            print_list('libri');
            break; 
          default:   
            // echo ("nessuna selezione");
            break; 
  } */
  


?>








